function generateGraphic(){
	createP("pText","Escolha o metodo iterativo para calculo da raiz quadrada","body");
	document.getElementById("pText").align = "center";
	document.getElementById("pText").style.font="italic 24px arial,serif";
	document.getElementById("pText").style.fontWeight="900";
	//Select Method
	createP("pSelect","","body");
	var select = document.createElement("select");
	select.id="select";
	select.size = 2;
	select.setAttribute("onChange","metodo(this.id);");
	document.getElementById("pSelect").appendChild(select);
	var option = document.createElement("option");
	option.id = "bissecao";
	option.name = "bissecao";
	option.value = "bissecao";
	document.getElementById("select").appendChild(option);
	document.getElementById(option.id).innerHTML = "Bissecao";
	var option = document.createElement("option");
	option.id = "newton";
	option.name = "newton";
	option.value = "newton";
	document.getElementById("select").appendChild(option);
	document.getElementById(option.id).innerHTML = "Newton";
}
function metodo(id){
	if(document.getElementById(id).value=="bissecao")
		graphicBissecao();
	else
		graphicNewton();
}
function graphicBissecao(){
	if (document.getElementById("mainTable")!=null) {
		removeElement("mainTable");
		if (document.getElementById("pBissecao")!=null)
		{
			removeElement("pBissecao");
		}
		if (document.getElementById("pNewton")!=null)
		{
			removeElement("pNewton");
		}
		if(document.getElementById("resultTable")!=null){
			removeElement("resultTable");
			removeElement("pResult");
		}
	}
	createP("pBissecao","Calculo da raiz pelo metodo da bissecao","body");
	document.getElementById("pBissecao").align = "center";
	document.getElementById("pBissecao").style.font="italic 24px arial,serif";
	document.getElementById("pBissecao").style.fontWeight="900";
	createTable("mainTable","body","mainTbody");
	createTr("trInputNumber","mainTbody");
	createTd("tdInputText","trInputNumber","Digite o numero");
	document.getElementById("tdInputText").style.font="bold 14px arial,serif";
	createTd("tdInputNumber","trInputNumber","");
	document.getElementById("tdInputNumber").style.font="bold 14px arial,serif";
	createInput("inputNumber","text","","tdInputNumber","inputNumber","","10");
	createTr("trInterval","mainTbody");
	createTd("tdIntervalInf","trInterval","Digite o intervalo [");
	document.getElementById("tdIntervalInf").style.font="bold 14px arial,serif";
	createTd("tdInputIntervalInf","trInterval","");
	document.getElementById("tdInputIntervalInf").style.font="bold 14px arial,serif";
	createInput("inputIntervalInf","text","","tdInputIntervalInf","inputIntervalInf","","10");
	createTd("tdIntervalSup","trInterval",",");
	document.getElementById("tdIntervalSup").style.font="bold 14px arial,serif";
	createTd("tdInputtdIntervalSup","trInterval","");
	document.getElementById("tdInputtdIntervalSup").style.font="bold 14px arial,serif";
	createInput("inputIntervalSup","text","","tdInputtdIntervalSup","inputIntervalSup","","10");
	createTd("tdCloseInterval","trInterval","]");
	document.getElementById("tdCloseInterval").style.font="bold 14px arial,serif";
	createTr("trTol","mainTbody");
	createTd("tdTolText","trTol","Digite a tolerancia");
	document.getElementById("tdTolText").style.font="bold 14px arial,serif";
	createTd("tdInputTol","trTol","");
	document.getElementById("tdInputTol").style.font="bold 14px arial,serif";
	createInput("inputTol","text","","tdInputTol","inputTol","","10");
	document.getElementById("tdInputTol").colSpan="2";
	createTr("trCalcula","mainTbody");
	createTd("tdButton","trCalcula","");
	var inputButton = document.createElement("input");
	inputButton.id = "bissecao";
	inputButton.type = "button";
	inputButton.value = "Calcula";
	inputButton.setAttribute("onClick","bissecao()");
	document.getElementById("tdButton").appendChild(inputButton);
}
function graphicNewton(){
	if (document.getElementById("mainTable")!=null) {
		removeElement("mainTable");
		if (document.getElementById("pBissecao")!=null)
		{
			removeElement("pBissecao");
		}
		if (document.getElementById("pNewton")!=null)
		{
			removeElement("pNewton");
		}
		if(document.getElementById("resultTable")!=null){
			removeElement("resultTable");
			removeElement("pResult");
		}
	}
	createP("pNewton","Calculo da raiz pelo metodo de Newton","body");
	document.getElementById("pNewton").align = "center";
	document.getElementById("pNewton").style.font="italic 24px arial,serif";
	document.getElementById("pNewton").style.fontWeight="900";
	createTable("mainTable","body","mainTbody");
	createTr("trInputNumber","mainTbody");
	createTd("tdInputText","trInputNumber","Digite o numero");
	document.getElementById("tdInputText").style.font="bold 14px arial,serif";
	createTd("tdInputNumber","trInputNumber","");
	document.getElementById("tdInputNumber").style.font="bold 14px arial,serif";
	createInput("inputNumber","text","","tdInputNumber","inputNumber","","10");
	createTr("trValue","mainTbody");
	createTd("tdValue","trValue","Digite o valor inicial");
	document.getElementById("tdValue").style.font="bold 14px arial,serif";
	createTd("tdInputValue","trValue","");
	document.getElementById("tdInputValue").style.font="bold 14px arial,serif";
	createInput("inputValue","text","","tdInputValue","inputValue","","10");
	createTr("trTol","mainTbody");
	createTd("tdTolText","trTol","Digite a tolerancia");
	document.getElementById("tdTolText").style.font="bold 14px arial,serif";
	createTd("tdInputTol","trTol","");
	document.getElementById("tdInputTol").style.font="bold 14px arial,serif";
	createInput("inputTol","text","","tdInputTol","inputTol","","10");
	document.getElementById("tdInputTol").colSpan="2";
	createTr("trCalcula","mainTbody");
	createTd("tdButton","trCalcula","");
	var inputButton = document.createElement("input");
	inputButton.id = "newton";
	inputButton.type = "button";
	inputButton.value = "Calcula";
	inputButton.setAttribute("onClick","newton()");
	document.getElementById("tdButton").appendChild(inputButton);
}
function createInput(id,type,value,idParent,name,readonly,size){
	var input = document.createElement("input");
	input.id = id;
	input.type=type;
	input.value= value;
	input.name=name;
	input.readOnly=readonly;
	input.size=size;
	document.getElementById(idParent).appendChild(input);
	return false;
}
function createTable(idTable,idParent,idTbody){
	var table= document.createElement("table");
	table.id=idTable;
	if (idParent=="body"){
		document.getElementsByTagName(idParent)[0].appendChild(table);
	}
	else{
		document.getElementById(idParent).appendChild(table);	
	}
	var tbody= document.createElement("tbody");
	tbody.id=idTbody;
	document.getElementById(idTable).appendChild(tbody);
	return false;
}
function createTr(id,idParent){
	var tr = document.createElement("tr");
	tr.id = id;
	document.getElementById(idParent).appendChild(tr);
	return false;
}
function createTd(id,idParent,text){
	var td = document.createElement("td");
	td.id = id;
	document.getElementById(idParent).appendChild(td).innerHTML = text;
	return false;
}
function createTh(id,idParent,text){
	var th = document.createElement("th");
	th.id = id;
	document.getElementById(idParent).appendChild(th).innerHTML = text;
	return false;
}
function createP(idP,textP,idParent){
	//create a first tag <p>
	var temp = document.createElement("p");
	temp.id = idP;
	if (idParent=="body"){
		document.getElementsByTagName(idParent)[0].appendChild(temp);
	}
	else{
		document.getElementById(idParent).appendChild(temp);	
	}
	if (textP != "") {
		document.getElementById(temp.id).innerHTML = textP;
	}
	return false;
}
function setStyle(id,position,width,height,left,top){
	document.getElementById(id).style.font = "13px arial,serif";
	document.getElementById(id).style.position=position;
	document.getElementById(id).style.width=width;
	document.getElementById(id).style.height=height;
	document.getElementById(id).style.left=left;
	document.getElementById(id).style.top=top;
	return false;
}
function removeElement(id){
	var tmp = document.getElementById(id);
	if (tmp != null){
		tmp.parentNode.removeChild(tmp);
	}
}